# fake ftssearch module
# Copyright (C) 2010  Chris Clark

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import re
import shutil
from cgi import escape as escape_html


def setup(dir_name):
    pass


def search(fts_handle, search_term):
    """Returns html search results.
    Fake returns static results
    """
    return '<p>Search not implemented in fake_search module ftsearch.py, implement your own (or install Whoosh)!</p>'


# hard coded static list for debugging/testing/demo.
# Ideally use a real FTS like Whoosh, solr, etc.
# this shows the data structures that are used/expected
# Or even a wrapper library like Haystack, pyndexter, etc.
_fake_data = {
                # dictionary of lists or tuples (count, description_word)
                'a': [(30, u'at'), (24, u'all'), (12, u'after'), (12, u'about'), (9, u'away'), (9, u'androcles'), (6, u'ass'), (6, u'am'), (5, u'another'), (5, u'ah')],
                'b': [(45, u'but'), (10, u'birds'), (8, u'big'), (8, u'beasts'), (7, u'blew'), (7, u'began'), (6, u'been'), (5, u'better'), (4, u'belly'), (4, u'before')],
                'f': [(16, u'fox'), (10, u'farmer'), (9, u'frogs'), (8, u'food'), (5, u'frog'), (5, u'friends'), (5, u'found'), (5, u'fly'), (5, u'fine'), (4, u'friend')],
                    }


def gen_find_top_search_terms(index_name, searchterm, maxnum=5):
    """Fake uses static data
    """
    item_list = _fake_data[searchterm]
    item_list = item_list[:maxnum]  # take top maxnum'th items
    
    return item_list
###########################################################
